<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends Controller {

	function Home()
	{
		parent::Controller();	
        $this->load->helper(array('form','url','security'));
	}
    
    function index()
    {
        echo "This is home index";
    }

	function login()
	{
	   if($this->session->userdata['userid'])
       {
        redirect('/home/index','refresh');
       }else
       {
        $this->load->view('login_form');
       }

	}
    
    function reg()
    {
        $this->load->view('reg_form');
    }
    
    function adduser()
    {
        if($this->input->post('user')&&$this->input->post('pass')&&$this->input->post('email'))
        {
            $this->load->model('User','',True);
            $this->User->add();
            redirect('note/mine','refresh');
        }else
        {
            redirect('home/index','refresh');
        }
    }
    
    function check()
    {
        $this->load->helper('url');
        $username = $this->input->post('user');
        $password = $this->input->post('pass');
        
        if($username&&$password){
            $md5pswd = md5($password);
            $query = $this->db->get_where('user',array('user'=>$username,'pass'=>$md5pswd));
            
            if($query->num_rows()==1){
            $row = $query->row_array();
            $uid = $row['id'];
            $user = $row['user'];
            $email = $row['email'];
            $regtime = $row['regtime']; 
               
            $newdata = array(
                'userid' => $uid,
                'username' => $user,
                'email' => $email,
                'regtime' => $regtime,
                'logedin' => True
                );
                  
                $this->session->set_userdata($newdata);
                redirect('note/mine','refresh');
            }else
            {
                redirect('home/login','refresh');
            } 
        }else
        {
            redirect('home/login','refresh');
        }      
    }
    
    function thankyou()
    {
        echo "Done!";
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */